﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Speech.Recognition;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SpeechProcessor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SpeechRecognitionEngine speechRecognitionEngine = null;
            speechRecognitionEngine = CreateSpeechEngine("de-DE");
            speechRecognitionEngine.AudioLevelUpdated += new EventHandler<AudioLevelUpdatedEventArgs>(engine_AudioLevelUpdated);
            speechRecognitionEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized);
            loadGrammarAndCommands();
            speechRecognitionEngine.SetInputToDefaultAudioDevice();
            speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
        }

        private void loadGrammarAndCommands()
        {
            throw new NotImplementedException();
        }

        private void engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            throw new NotImplementedException();
        }

        private void engine_AudioLevelUpdated(object sender, AudioLevelUpdatedEventArgs e)
        {
            throw new NotImplementedException();
        }

        private SpeechRecognitionEngine CreateSpeechEngine(string preferedCulture)
        {
            SpeechRecognitionEngine speechRecognitionEngine = null;

            foreach (RecognizerInfo config in SpeechRecognitionEngine.InstalledRecognizers())
            {
                if (config.Culture.ToString().Equals(preferedCulture))
                {
                    speechRecognitionEngine = new SpeechRecognitionEngine(config);
                    break;
                }
            }

            if (speechRecognitionEngine == null)
            {
                MessageBox.Show("The desired culture is not installed " +
                                "on this machine, the speech-engine will continue using "
                                + SpeechRecognitionEngine.InstalledRecognizers()[0].Culture.ToString() +
                                " as the default culture.", "Culture " + preferedCulture + " not found!");
                speechRecognitionEngine = new SpeechRecognitionEngine();
            }

            return speechRecognitionEngine;
        }
    }
}
